/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forms;

import com.sun.lwuit.Command;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import entidade.MobCatController;
import entidade.Registro;
import exceptions.ReturnWsException;


/**
 *
 * @author ademar.victorino
 */
public class DetalheRegistroForm extends AbstractForm {

    private Registro reg;
    private AbstractForm returnForm = null;

    public DetalheRegistroForm() {
        super();
        commands();
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    }

    private void commands() {
        addCommand(new Command("Voltar") {

            public void actionPerformed(ActionEvent evt) {
                returnForm.show();
            }
        });

        addCommand(new Command("Mapa") {

            public void actionPerformed(ActionEvent evt) {

                new MapaForm().show(reg, returnForm);

            }
        });

        addCommand(new Command("Discar") {

            public void actionPerformed(ActionEvent evt) {

                new DiscarForm().show(reg, returnForm);

            }
        });
    }

    public void show(Registro regVO, AbstractForm returnForm) {
        this.reg = regVO;
        this.returnForm = returnForm;
        init();
        super.show();
    }

    protected void init() {
        try {
            reg = MobCatController.getInstance().getRegistro(reg.id);
        } catch (ReturnWsException ex) {
            ex.showError(returnForm);
        }
        setTitle(reg.nome);

        Label lName = new Label("Nome: " + reg.nome);
        addComponent(lName);

        if (isBlancOrNull(reg.telefone)) {
            addComponent(new Label("Telefone: " + reg.telefone));
        }
        if (isBlancOrNull(reg.telefone2)) {
            addComponent(new Label("Telefone: " + reg.telefone2));
        }
        
        if (isBlancOrNull(reg.endereco)) {
            TextArea ts = new TextArea("Endereço: " + reg.endereco);
            ts.setEditable(false);
            ts.getStyle().setBgColor(0xffffff);
            ts.getStyle().setBgSelectionColor(0xffffff);
            ts.getStyle().setFgSelectionColor(ts.getStyle().getFgColor());
            ts.getStyle().setBorder(lName.getStyle().getBorder());
            ts.setRows(2);
            addComponent(ts);
        }
        if (isBlancOrNull(reg.bairro)) {
            addComponent(new Label("Bairro: " + reg.bairro));
        }
        if (isBlancOrNull(reg.site)) {
            addComponent(new Label("Site: " + reg.site));
        }
        if (isBlancOrNull(reg.email)) {
            addComponent(new Label("Email: " + reg.email));
        }
        if (isBlancOrNull(reg.resumo)) {
            TextArea ts = new TextArea("Comentários dos Clientes:\n" + reg.resumo);
            ts.setEditable(false);
            ts.getStyle().setBgColor(0xffffff);
            ts.setRows(2);
            ts.getStyle().setBgSelectionColor(0xffffff);
            ts.getStyle().setFgSelectionColor(ts.getStyle().getFgColor());
            ts.getStyle().setBorder(lName.getStyle().getBorder());
            addComponent(ts);
        }
        show();
    }

    boolean isBlancOrNull(String s) {
        return !(s == null || s.trim().length() == 0);
    }
}
